package org.jeecg.eqp.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.jeecg.eqp.dto.EqpMachinestateValueDTO;
import org.jeecg.eqp.entity.EqpMachinestateValue;
import org.jeecg.eqp.service.IEqpMachinestateValueService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.eqp.vo.EqpMachinestateValueVO;
import org.jeecg.report.dto.EqpFaultHistoryDTO;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 设备运行状态
 * @Author: LiCY
 * @Date:   2023-06-29
 * @Version: V1.0
 */
@Api(tags="设备运行状态")
@RestController
@RequestMapping("/eqp/eqpMachinestateValue")
@Slf4j
public class EqpMachinestateValueController extends JeecgController<EqpMachinestateValue, IEqpMachinestateValueService> {
	@Autowired
	private IEqpMachinestateValueService eqpMachinestateValueService;

	 /**
	  * 分页列表查询
	  *
	  * @param eqpMachinestateValueVO
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 @ApiOperation(value="设备运行状态追溯", notes="设备运行状态追溯")
	 @GetMapping(value = "/eqpMachinestateTrace")
	 @DS("#header.his")
	 public Result<IPage<EqpMachinestateValueDTO>> eqpMachinestateTrace(EqpMachinestateValueVO eqpMachinestateValueVO,
																		@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
																		@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
																		HttpServletRequest req) {
		 Page<EqpMachinestateValueDTO> page = new Page<>(pageNo, pageSize);
		 IPage<EqpMachinestateValueDTO> pageList = eqpMachinestateValueService.eqpMachinestateTrace(page, eqpMachinestateValueVO);
		 return Result.OK(pageList);
	 }

	/**
	 * 分页列表查询666
	 *
	 * @param eqpMachinestateValueVO
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "设备运行状态-分页列表查询")
	@ApiOperation(value="设备运行状态-分页列表查询", notes="设备运行状态-分页列表查询")
	@GetMapping(value = "/list")
	@DS("#header.his")
	public Result<IPage<EqpMachinestateValue>> queryPageList(EqpMachinestateValueVO eqpMachinestateValueVO,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		Page<EqpMachinestateValue> page = new Page<>(pageNo, pageSize);
		IPage<EqpMachinestateValue> pageList = eqpMachinestateValueService.queryPageList(page, eqpMachinestateValueVO);
		return Result.OK(pageList);
	}

	 /**
	  * 分页列表查询666
	  *
	  * @param eqpMachinestateValueVO
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "设备运行状态-分页列表查询")
	 @ApiOperation(value="设备运行状态-分页列表查询", notes="设备运行状态-分页列表查询")
	 @GetMapping(value = "/faultList")
	 @DS("#header.his")
	 public Result<IPage<EqpFaultHistoryDTO>> queryPagefaultList(EqpMachinestateValueVO eqpMachinestateValueVO,
																 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
																 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
																 HttpServletRequest req) {
		 Page<EqpFaultHistoryDTO> page = new Page<>(pageNo, pageSize);
		 IPage<EqpFaultHistoryDTO> pageList = eqpMachinestateValueService.queryPagefaultList(page, eqpMachinestateValueVO);
		 return Result.OK(pageList);
	 }

    /**
    * 导出excel
    *
    * @param request
    * @param eqpMachinestateValueVO
    */
    @RequestMapping(value = "/exportXls")
    @DS("#header.his")
    public ModelAndView exportXls(HttpServletRequest request, EqpMachinestateValueVO eqpMachinestateValueVO) {
		// Step.1 组装查询条件
		LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		// Step.2 获取导出数据
		Page<EqpMachinestateValue> page = new Page<>(1, 900000);
		IPage<EqpMachinestateValue> list = eqpMachinestateValueService.queryPageList(page, eqpMachinestateValueVO);
		// Step.3 AutoPoi 导出Excel
		ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		String title = "设备状态源数据";
		//此处设置的filename无效 ,前端会重更新设置一下
		mv.addObject(NormalExcelConstants.FILE_NAME, title);
		mv.addObject(NormalExcelConstants.CLASS, EqpMachinestateValue.class);
		ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
		mv.addObject(NormalExcelConstants.PARAMS, exportParams);
		mv.addObject(NormalExcelConstants.DATA_LIST, list.getRecords());
		return mv;
    }

	 /**
	  * 导出excel
	  *
	  * @param request
	  * @param eqpMachinestateValueVO
	  */
	 @RequestMapping(value = "/exportTraceXls")
	 @DS("#header.his")
	 public ModelAndView exportTraceXls(HttpServletRequest request, EqpMachinestateValueVO eqpMachinestateValueVO) {
		 // Step.1 组装查询条件
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();


		 // Step.2 获取导出数据
		 Page<EqpMachinestateValueDTO> page = new Page<>(1, 900000);
		 IPage<EqpMachinestateValueDTO> list = eqpMachinestateValueService.eqpMachinestateTrace(page, eqpMachinestateValueVO);

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 //此处设置的filename无效 ,前端会重更新设置一下
		 String title = "设备状态追溯";
		 mv.addObject(NormalExcelConstants.FILE_NAME, title);
		 mv.addObject(NormalExcelConstants.CLASS, EqpMachinestateValueDTO.class);
		 //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
		 ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
		 //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
		 mv.addObject(NormalExcelConstants.PARAMS, exportParams);
		 mv.addObject(NormalExcelConstants.DATA_LIST, list.getRecords());
		 return mv;
	 }


 }
